#include <reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit EN=P1^5;
sbit RS=P1^0;
sbit RW=P1^1;
sbit BUSY=P0^7;

void wait()
{
	P0=0xff;
	do
	{
		RS=0;
		RW=1;
		EN=0;
		EN=1;
	}while(BUSY);
	EN=0;
}

void write_cmd(uint8 cmd)
{
	wait();
	EN=0;
	RS=0;
	RW=0;
	P0=cmd;
	EN=1;
	EN=0;
}

void init_LCD()
{
	write_cmd(0x38);
	write_cmd(0x0c);
	write_cmd(0x06);
	write_cmd(0x01);
}

void write(uint8 dat)
{
	wait();
	EN=0;
	RS=1;
	RW=0;
	P0=dat;
	EN=1;
	EN=0;
}

void showString(uint8 stataddr,uint8 *p)
{
	write_cmd(stataddr);
	while(*p!='\0')
	{
		write(*p++);
	}
}

void main()
{
	uint8 str[]="Hello Word!";
	uint8 strn[]="QinNaiLin";
	init_LCD();
	while(1)
	{
		showString(0x80,str);
		showString(0xc0,strn);
	}
}